@echo off

rem Set VS2015 BuildCustomizations path
set "BC_PATH=C:/Program Files (x86)/MSBuild/Microsoft.Cpp/v4.0/V140/BuildCustomizations"
rem VS2019 BuildCustomizations path
rem set "BC_PATH=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Microsoft/VC/v160/BuildCustomizations"

mkdir "%BC_PATH%\temp"
rem Move all cuda files from BuildCustomizations folder to temp folder
for /r "%BC_PATH%" %%F in (*cuda*.xml *cuda*.props *cuda*.targets) do move "%%F" "%BC_PATH%\temp"
rem Move files containing 10.2 from temp folder to parent folder, so only 10.2 build files remain
for /r "%BC_PATH%\temp" %%F in (*10.2*) do copy "%%F" "%BC_PATH%"


set BUILD_PATH=build-cuda10-trt7
REM Delete build directory
rmdir /s /q %BUILD_PATH%

cmake -G "Visual Studio 14 2015 Win64" -DINFERENCE_BACKEND=CUDA -DMY_CUDA_VERSION="10.2" -DMY_TRT_VERSION="7" -B %BUILD_PATH%  . 
cd %BUILD_PATH%
cmake --build . --config Release -j 34
cmake --install .

rem Move all files from temp folder back to parent folder to restore
for /r "%BC_PATH%\temp" %%F in (*) do copy "%%F" "%BC_PATH%"
rmdir /s /q "%BC_PATH%\temp"

rem ===============================================================

mkdir "%BC_PATH%\temp"
rem Move all cuda files from BuildCustomizations folder to temp folder
for /r "%BC_PATH%" %%F in (*cuda*.xml *cuda*.props *cuda*.targets) do move "%%F" "%BC_PATH%\temp"
rem Move files containing 11.1 from temp folder to parent folder, so only 11.1 build files remain
for /r "%BC_PATH%\temp" %%F in (*11.1*) do copy "%%F" "%BC_PATH%"


cd ..
set BUILD_PATH=build-cuda11-trt7

rmdir /s /q %BUILD_PATH%
cmake -G "Visual Studio 14 2015 Win64" -DINFERENCE_BACKEND=CUDA -DMY_CUDA_VERSION="11.1" -DMY_TRT_VERSION="7" -B %BUILD_PATH% . 
cd %BUILD_PATH%
cmake --build . --config Release -j 34
cmake --install .

cd ..
set BUILD_PATH=build-cuda11-trt8
rmdir /s /q %BUILD_PATH%
cmake -G "Visual Studio 14 2015 Win64" -DINFERENCE_BACKEND=CUDA -DMY_CUDA_VERSION="11.1" -DMY_TRT_VERSION="8" -B %BUILD_PATH% . 
cd %BUILD_PATH%
cmake --build . --config Release -j 34
cmake --install .


rem Move all files from temp folder back to parent folder to restore
for /r "%BC_PATH%\temp" %%F in (*) do copy "%%F" "%BC_PATH%"
rmdir /s /q "%BC_PATH%\temp"